//
//  STGoodsView.m
//  赛拓
//
//  Created by 王磊 on 8/7/16.
//  Copyright © 2016 立金所. All rights reserved.
//

#import "STGoodsView.h"
#import "STCommodityBean.h"
#import "STGoodView.h"
@interface STGoodsView()<STBaseViewDelegate>
@property (nonatomic ,strong) STCommodityBean *goods;

//@property (nonatomic ,strong)

@end
@implementation STGoodsView
- (void)commitInit {
    [super commitInit];
    
    for (int i = 0; i < 3; i++) {
        
        STGoodView *goodView = [STGoodView instance];
        
        goodView.mDelegate = self;
        
        [self addSubview:goodView];
    }
}

- (void)updateData:(id)data {
    
    NSArray *array = data;
    [self.subviews enumerateObjectsUsingBlock:^(__kindof STGoodView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if (array.count == 3 ) {
            [obj updateData:array[idx]];
            
            obj.hidden = false;
            
        }else if (array.count == 0) {
            
            obj.hidden = true;
            
        } else {
            
            if (array.count > idx) {
                [obj updateData:array[idx]];
                obj.hidden = false;
            } else {
                obj.hidden = true;
            }
        }
    }];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    @WeakObj(self)
    [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        obj.frame = CGRectMake(0, idx * 280 * ST_RATE , selfWeak.k_width, 280 * ST_RATE);
        
    }];
}
- (void)onItemClick:(STItemClickType)itemType withData:(id)data forIndexPath:(NSIndexPath *)indexPath {
    
    [self.mDelegate onItemClick:STItemClickTypeGoods withData:data forIndexPath:nil];
}
@end
